#!/bin/bash
[ $# -eq 0 ] && { echo "Usage: $0 ORIG_LANG WORDSFILE"; exit 1; }

LANG=c

cat $2 | while read WORD
do
	echo $WORD
	rm Test-en/$WORD/LEXELT-test.xml
	
	echo '<corpus lang="english">' >> Test-en/$WORD/LEXELT-test.xml
	echo '<lexelt item="LEXELT">' >> Test-en/$WORD/LEXELT-test.xml

	grep 'senseid=' Test-$1/$WORD/LEXELT-test.xml \
	| sed 's/.*instance=\"\([0-9]*\)\".*senseid=\"\([0-9]*\)\".*/\1 \2/' | while read INSTANCE SENSEID
	do
		grep -B 1 -A 4 "instance=\"$INSTANCE\"" Test-en/$WORD/$WORD-corpus.xml \
		| sed -e "s_\(.*\)senseid=\"NOTAG\"\(.*\)_\1senseid=\"$SENSEID\"\2_" >> Test-en/$WORD/LEXELT-test.xml
	done
	
	echo '</lexelt>' >> Test-en/$WORD/LEXELT-test.xml
	echo '</corpus>' >> Test-en/$WORD/LEXELT-test.xml
done
